class Solution {
public:
    int timeRequiredToBuy(vector<int>& tickets, int k) {
        int ret = 0;
        queue<pair<int, int>> q;
        for (int i = 0; i < tickets.size(); i++)
            q.push({ tickets[i], i });
        while (q.size())
        {
            auto front = q.front();
            q.pop();
            front.first--;
            ret++;
            if (front.first > 0) q.push(front);
            else {
                if (front.second == k) break;
            }
        }
        return ret;
    }
};

class Solution {
public:
    bool CheckPermutation(string s1, string s2) {
        int hash1[26] = { 0 };
        int hash2[26] = { 0 };
        for (auto& ch : s1) hash1[ch - 'a']++;
        for (auto& ch : s2) hash2[ch - 'a']++;
        for (int i = 0; i < 26; i++)
            if (hash1[i] != hash2[i])
                return false;
        return true;
    }
};